<?php
/**
 * @author    : liuqiangde<liuqiangde@dalingpao.com>
 * @copyright : 2017-08-21
 */
?>
<div style="text-align:center;padding: 5px;">
    <h2>用户列表</h2>
</div>
<div style="position:absolute;left:70%;top:60px;"><a href="./?c=Home&a=add">
        <button>添加新用户</button>
    </a></div>
<div style="position:absolute;left:300px;">
    <table style="text-align:center;border-color:#98bf21;width:1200px;left:100px" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <th>ID</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>民族</th>
            <th>手机号</th>
            <th>操作</th>
        </tr>
        <?php foreach ($list as $val) { ?>
            <tr>
                <td><?php echo $val['id']; ?></td>
                <td><?php echo $val['name']; ?></td>
                <td><?php echo $val['gender']; ?></td>
                <td><?php echo $val['age']; ?></td>
                <td><?php echo $val['nation']; ?></td>
                <td><?php echo $val['number']; ?></td>
                <td>
                    <a href='./?c=Home&a=Edit&userId=<?php echo $val['id']; ?>'><span class='edit' style="color:blueviolet">修改</span></a>
                    | <span class='delete' style="color:red" data-user_id=<?php echo $val['id']; ?>>删除</span>
                </td>
            </tr>
        <?php } ?>
    </table>
</div>

<script>

    $('.delete').on('click', function ()
    {
        var res    = confirm('确认删除该信息吗?');
        //获取uid
        var userId = $(this).data("user_id");
        //判断是否确认

        if (res) {
            $.ajax({
                type    : 'GET',
                url     : './?c=Home&a=Del',
                data    : {
                    userId : userId
                },
                success : function (data)
                {
                    console.log(data);
                    location.href = '';
                },
                fail    : function ()
                {
                    alert('删除失败!');
                }
            });
        } else {
            window.location.reload();
        }
    });
</script>
